if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
    set(ANDROID_NDK_HOST "windows-x86_64")
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
    set(ANDROID_NDK_HOST "linux-x86_64")
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
    set(ANDROID_NDK_HOST "darwin-x86_64")
else()
    message(FATAL_ERROR "Unsupported host platform: ${CMAKE_HOST_SYSTEM_NAME}")
endif()

add_definitions(-DFLOATING_POINT)
add_definitions(-DUSE_SMALLFT)
# CMake最低版本要求
cmake_minimum_required(VERSION 3.4.1)

# 打印一些调试信息
message(STATUS "Source Directory: ${CMAKE_CURRENT_SOURCE_DIR}")
message(STATUS "Android ABI: ${ANDROID_ABI}")
message(STATUS "Android API LEVEL: ${ANDROID_NATIVE_API_LEVEL}")

message(STATUS "ANDROID_NDK clang: ${ANDROID_NDK}/toolchains/llvm/prebuilt/${ANDROID_NDK_HOST}/bin/clang")

# 设置项目名称和语言
project(SpeexDSPAndroid C CXX)

enable_language(C)


# 使用Clang编译器
set(CMAKE_C_COMPILER ${ANDROID_NDK}/toolchains/llvm/prebuilt/${ANDROID_NDK_HOST}/bin/clang)
set(CMAKE_CXX_COMPILER ${ANDROID_NDK}/toolchains/llvm/prebuilt/${ANDROID_NDK_HOST}/bin/clang++)


# 包含头文件目录
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")

# 搜索源文件
file(GLOB_RECURSE ALL_PROJ_SRC "${CMAKE_CURRENT_SOURCE_DIR}/libspeexdsp/*.c" "${CMAKE_CURRENT_SOURCE_DIR}/native-lib.cpp")

# 添加编译选项 (根据需要启用)
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror")

# 添加库（共享库或静态库）
add_library(speexdspand SHARED ${ALL_PROJ_SRC})

message(STATUS "log-lib: ${log-lib}")
message(STATUS "log: ${log}")

message(STATUS "============")

# 查找log库 (来自NDK)
find_library(log-lib log)

message(STATUS "log-lib: ${log-lib}")
message(STATUS "log: ${log}")

# 链接库到目标库
target_link_libraries(speexdspand ${log-lib})

# 如果需要，可以添加更多的第三方库或系统库
# find_library(other-lib other)
# target_link_libraries(speexdspand ${other-lib})
